package com.wwwarehouse.contract.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.contract.bean.GetShopIdBean;

import java.util.ArrayList;

import contract.wwwarehouse.com.contract.R;

/**
 * 订单导入设置主页Adapter
 * Created by ShineF on 2017/8/11 0011.
 */

public class ImportOrdersPagersAdapter
        extends RecyclerView.Adapter<ImportOrdersPagersAdapter.ImportOrdersPagersHolder> {

    private Context mContext = null;
    private ArrayList<GetShopIdBean.ListBean> mList = null;
    private int mHeight = 0;
    private OnItemClickListener mListener = null;
    private int mType = 0;

    public ImportOrdersPagersAdapter(Context context, ArrayList<GetShopIdBean.ListBean> list, int height, int type) {
        this.mContext = context;
        this.mList = list;
        this.mHeight = height;
        this.mType = type;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public ImportOrdersPagersHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ImportOrdersPagersHolder(
                View.inflate(mContext, R.layout.adapter_import_orders_pager_recycle, null));
    }

    @Override
    public void onBindViewHolder(ImportOrdersPagersHolder holder, final int position) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.mImportOrdersItem.getLayoutParams();
        params.height = (mHeight - ConvertUtils.dip2px(mContext, 20)) / 3;
        final GetShopIdBean.ListBean listBean = mList.get(position);
        holder.mImportOrdersItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.ItemClickListener(position, v, listBean);
                }
            }
        });
        holder.mImportOrdersName.setText(listBean.getShopName());
        if (mType == 1) {
            holder.mImportOrdersIsSetting.setVisibility(View.INVISIBLE);
        } else if (mType == 2) {
            holder.mImportOrdersIsSetting.setVisibility(View.VISIBLE);
        }
        if (0 == (listBean.getStatus())) {
            holder.mImportOrdersIsSetting.setText(mContext.getString(R.string.import_pagers_info_unsetting));
            holder.mImportOrdersIsSetting.setTextColor(ContextCompat.getColor(mContext, R.color.common_color_c7_96999e));
        } else {
            holder.mImportOrdersIsSetting.setText(mContext.getString(R.string.import_pagers_info_setting));
            holder.mImportOrdersIsSetting.setTextColor(ContextCompat.getColor(mContext, R.color.common_color_c1_337cff));
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public interface OnItemClickListener {
        void ItemClickListener(int position, View view, GetShopIdBean.ListBean data);
    }

    class ImportOrdersPagersHolder extends RecyclerView.ViewHolder {

        TextView mImportOrdersName;
        ImageView mImportOrdersLogo;
        RelativeLayout mImportOrdersItem;
        TextView mImportOrdersIsSetting;

        ImportOrdersPagersHolder(View itemView) {
            super(itemView);
            mImportOrdersName = (TextView) itemView.findViewById(R.id.tv_import_orders_name);
            mImportOrdersIsSetting = (TextView) itemView.findViewById(R.id.tv_is_setting);
            mImportOrdersLogo = (ImageView) itemView.findViewById(R.id.iv_import_orders_logo);
            mImportOrdersItem = (RelativeLayout) itemView.findViewById(R.id.rl_item);
        }
    }
}
